<template>
	<view>
		<view class="cu-custom" :style="{height: $wanlshop.wanlsys().height + 'px' }">
			<view class="cu-bar fixed" :style="{
				height: $wanlshop.wanlsys().height + 'px', 
				paddingTop: $wanlshop.wanlsys().top + 'px',
				color: '#333333',
				backgroundImage: 'url(' + $wanlshop.oss('/uploads/20230921/acd98ace6f530a4929301645e2d81244.png') + ')'
			}">
				<view class="action">
					<text class="wlIcon-fanhui1" @tap="$wanlshop.back(1)"></text>
				</view>
				<view class="content text-bold" :style="{top: $wanlshop.wanlsys().top + 'px'}">
					{{title}}
				</view>

			</view>
		</view>
		<!-- 轮播图 -->
		<view class="wrap">
			<!-- <image class="wrapImg" :src="$wanlshop.oss(image)" mode="aspectFill"></image> -->
			<swiper class="screen-swiper square-dot" :indicator-dots="true" :circular="true" :autoplay="true"
				interval="5000" duration="500">
				<swiper-item v-for="(item,index) in image" :key="'s'+index">
					<image :src="$wanlshop.oss(item)" mode="aspectFill" class="wrapImg"></image>
				</swiper-item>
			</swiper>
		</view>


		<!-- 圈子消息 -->
		<view class="circle" v-for="(item,index) in list" :key="'c'+index"
			@click="jump('/pages/circle/details?id='+item.id)">
			<view class="circleItem">
				<view class="circleItemTitle">{{item.title}}</view>
				<view class="circleItemContent">{{item.content}}</view>
				<view class="circleItemCome">来自<text>{{item.category_text}}</text></view>
				<view class="circleItemImg">
					<block v-for="(itm,idx) in item.images" :key="'m'+idx">
						<image :src="$wanlshop.oss(itm)" mode="aspectFill" @click.stop="onPreviewTap(item.images,idx)">
						</image>
					</block>
				</view>
				<view class="circleItemFooter">
					<view class="footerFlex">
						<image :src="item.user.avatar" class="footerFlexImg"></image>
						<view class="footerFlexName">{{item.user.nickname}}</view>
						<view class="iconfont icon-liulan1"></view>
						<view class="footerFlexNum">{{item.browse}}</view>
						<view class="iconfont icon-shoucang3"></view>
						<view class="footerFlexNum">{{item.like}}</view>
						<view class="iconfont icon-comment"></view>
						<view class="footerFlexNum">{{item.comment}}</view>
					</view>
				</view>
			</view>
		</view>
		<wanl-empty :text="empty" src="collect_default3x" v-if="list.length === 0 && status !== 'loading'" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: "",
				image: '',
				id: "",
				list: [],
				page: 1,
				empty: '没有找到圈子消息',
				reload: true, //判断是否上拉
				last_page: 0,
				status: 'loading',
				contentText: {
					contentdown: '',
					contentrefresh: '正在加载..',
					contentnomore: '没有更多数据了'
				},

			}
		},
		onLoad(e) {
			console.log(e)
			this.title = e.name
			this.id = e.id
			// this.image = e.image
			this.circleLists()
			this.circleDetail()
		},
		// 下拉刷新
		onReachBottom() {
			if (this.page >= this.last_page) {
				this.status = 'noMore';
			} else {
				this.reload = false;
				this.contentText.contentdown = '上拉显示更多';
				this.page = this.page + 1; //页码+1
				this.status = 'loading';
				this.circleLists();
			}
		},
		methods: {
			jump(url) {
				this.$wanlshop.auth(url)
				// uni.navigateTo({
				// 	url: url
				// })
			},
			
			async circleDetail() {
				await uni.request({
					url: '/information/category/detail',
					method: 'post',
					data: {
						cate_id: this.id,
			
					},
					success: res => {
						console.log("cxzczxc",res)
						if (res.data && res.data.images) {
							const arr = res.data.images.split(',')
							const newArr = arr.map(itm => {
								return this.$wanlshop.oss(itm)
							})
							console.log(newArr)
							this.image = newArr
						}else{
							this.image = []
						}
					}
				});
			},
			// 圈子列表
			async circleLists() {
				await uni.request({
					url: '/addons/circle/api.index/lists',
					method: 'post',
					data: {
						page: this.page,
						category_id: this.id,

					},
					success: res => {
						console.log("circleLists", res)
						this.status = 'more';
						res.data.data.forEach((item, index) => {
							if (item.images) {
								const arr = item.images.split(',')
								const newArr = arr.map(itm => {
									return this.$wanlshop.oss(itm)
								})
								console.log(newArr)
								item.images = newArr
							}
						})
						this.list = this.reload ? res.data.data : this.list.concat(res.data
							.data); //数据 追加
						if (res.data.data.length == 0) {
							this.empty = `没有找到圈子消息`;
						}
						this.page = res.data.current_page; //当前页码
						this.last_page = res.data.last_page; //总页码
						console.log("this.list", this.list)
					}
				});
			},
			// 预览图片
			onPreviewTap(url, index) {
				uni.previewImage({
					current: index,
					urls: url,
					loop: true
				})
			},
		}
	}
</script>

<style lang="scss">
	.navTitle {
		width: 90rpx;
		height: 56rpx;
		border-radius: 8rpx;
		border: 2rpx solid #4CBD66;
		text-align: center;
		line-height: 52rpx;
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #4CBD66;
	}

	.wrap {
		padding: 10rpx 0;

		.wrapImg {
			width: 100%;
			height: 208rpx;
		}
		.screen-swiper {
			width: 100%;
			height: 208rpx;
			min-height: 0;
			max-height: 208rpx;
		}
	}

	// 圈子消息
	.circle {
		padding: 28rpx 30rpx 16rpx 30rpx;
		background: #fff;
		margin-top: 20rpx;
		height: auto;

		.circleItem {
			width: 100%;
			height: auto;

			.circleItemTitle {
				font-size: 34rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: bold;
				color: #333333;
				line-height: 40rpx;
			}

			.circleItemContent {
				font-size: 30rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #777777;
			}

			.circleItemCome {
				font-size: 26rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #777777;
				margin-top: 8rpx;

				text {
					font-size: 28rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #4CBD66;
					margin-left: 8rpx;
				}
			}

			.circleItemImg {
				width: 100%;
				height: auto;
				display: flex;
				flex-wrap: wrap;

				image {
					width: 210rpx;
					height: 210rpx;
					margin-top: 16rpx;
				}

				image:nth-child(2) {
					margin-left: 30rpx;
					margin-right: 30rpx;
				}

				image:nth-child(5) {
					margin-left: 30rpx;
					margin-right: 30rpx;
				}

				image:nth-child(8) {
					margin-left: 30rpx;
					margin-right: 30rpx;
				}
			}

			.circleItemFooter {
				width: 100%;
				border-top: 1rpx solid #e2e2e2;
				margin-top: 38rpx;
				height: auto;

				.footerFlex {
					margin-top: 16rpx;
					display: flex;
					align-items: center;

					.footerFlexImg {
						width: 42rpx;
						height: 42rpx;
						border-radius: 100%;
					}

					.footerFlexName {
						font-size: 24rpx;
						font-family: PingFang SC-Medium, PingFang SC;
						font-weight: 500;
						color: #888888;
						margin-left: 8rpx;
					}

					.icon-liulan1 {
						margin-left: auto;
						font-size: 32rpx;
					}

					.footerFlexNum {
						font-size: 26rpx;
						font-family: PingFang SC-Bold, PingFang SC;
						color: #777777;
						margin-left: 10rpx;
					}

					.icon-shoucang3 {
						margin-left: 44rpx;
						font-size: 32rpx;
					}

					.icon-comment {
						margin-left: 54rpx;
						font-size: 32rpx;
					}
				}
			}
		}
	}
</style>